package test.socket;

import java.io.IOException;
import java.net.Socket;

import hyl.base.net.nio.NIOData1;
import hyl.core.MyCharset;
import hyl.core.MyDate;
import hyl.core.MyFun;
import hyl.core.net.BioClient;
import hyl.core.net.MySocket;
import hyl.core.net.NioClient;

public class testclient {

	public static void main(String[] args) throws IOException {
		/* 服务器地址 */
		// testnio() ;
		// testbio() ;
		// testping();
		 testclone() ;
	}
	public static void testnio() throws IOException {

		NioClient _cli = new NioClient("localhost", 9090);
		_cli.setHandler((r,bb) -> {
			System.out.print("--");
			System.out.println(MyFun.bytes2Str(bb, MyCharset._UTF8));
			return false;
		});
		_cli.start();
		
		for (int i = 0; i < 5000; i++) {
			//MyDate.sleep(1);
			System.out.println("send"+i);
			_cli.send(("asd 谁的风格吧看你家噶说你还关机了小客车vj别人恐惧而突然看见你说的话就够啦" + i + "\n").getBytes());
			//MyDate.sleep(20);
		}
	}
	public static void testbio() throws IOException {

		BioClient _cli = new BioClient("localhost", 9090);
		_cli.setHandler((r,bb) -> {
			System.out.print("--");
			System.out.println(MyFun.bytes2Str(bb, MyCharset._UTF8));
			return false;
		});
		_cli.start();
	   int ii=	MyFun.getRandom(90);
		for (int i = 0; i < 5; i++) {
			_cli.send(("asd 谁的风格吧"+ii+"的话就够啦" + i + "\n").getBytes());
			MyDate.sleep(3000);
		}
	}
	 public static void testping() {
	        try {
	            Socket socket = new Socket("127.0.0.1",15000);
	            //i用于记录多少次时断开连接
	            int i=1;
	            while (true){
	                System.out.println("发送心跳"+i++);
	                //sendUrgentData 发送的数据不被 服务端输入流接收
	                socket.sendUrgentData(0xff);
	                if (i%2==0) {
	                	MySocket.sendUtf8(socket, (i+"test"));
	                	MySocket.sendBytes(socket,new byte[] { (byte) 0xff});
	                }
	                Thread.sleep(2000);
	            }
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }
public static void testclone() {
	NIOData1 nd=	new NIOData1();
	nd.setI类型((byte)1);
	byte[] s="在下次V中".getBytes();
	nd.setData(s);

		NIOData1 nd1=nd.clone();
		System.out.println(nd);
		System.out.println(nd1);
	System.out.println(nd1.getData());
	System.out.println(nd1.getB类型());
}
}
